<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>把外部CSS切成内嵌字符串</title>
</head>
<body>
<?php
$file = "poem.css";
if (!file_exists($file)) {
	exit("File： ".$file." is not exists.<br />");
} else {
	echo "OK，I can see it.<br />";
}
/*
@ $fp = fopen($file, 'rb', TRUE);
if (!$fp) {
	echo "I can't open the file = > ".$file;
	exit;
}
fpassthru($fp);
fclose($fp);
*/

//文件到数组
//$file_array = file($file);
//foreach ($file_array as $key => $value) {
//	echo "<br />[".$key."] => ".$value;
//}

//文件到字符串
$file_content = file_get_contents($file, FILE_USE_INCLUDE_PATH);
echo "<br /><span style=\"color:red;\">源文件信息：</span><br />".nl2br($file_content);

// 去除注释和换行
$file_content = preg_replace('/(\/\*(\s|.)*?\*\/)|\s/',' ',$file_content);
echo "<br /><span style=\"color:red;\">去除注释：</span><br />".$file_content;
//echo "<br /><span style=\"color:red;\">去除注释：</span><br />".preg_replace('/\/\/[^\n]*|\/\*([^\*^\/]*|[\*^\/*]*|[^\**\/]*)*\*\//','#',$file_content);
// '/\*([[:space:]]|.)*\*/'  

// 得到style
echo '<br /><br />Title:';
$css_title = array();
preg_match('/span\.poem\-title\s*\{(.*?)\}/', $file_content, $css_title);
print_r($css_title[1]);

echo '<br /><br />Author:';
//$css_title = array();
preg_match('/span\.poem\-author\s*\{(.*?)\}/', $file_content, $css_title);
print_r($css_title[1]);

echo '<br /><br />Content:';
//$css_title = array();
preg_match('/span\.poem\-content\s*\{(.*?)\}/', $file_content, $css_title);
print_r($css_title[1]);

class test_null {
	private $tnull;
	public function __construct($flag = true) {
		if ($flag == true) {
			$this->tnull = 'BBC';
		}
	}
	public function dispay () {
		echo "AAA+".$this->tnull."+AAA";
	}
}

$tnull = new test_null(false);
$tnull->dispay();
//$temp = preg_split('/span\.poem\-title\s*\{(.*?)\}/', $file_content, -1, PREG_SPLIT_DELIM_CAPTURE);
//print_r($temp);

?>
</body>
</html>